package com.cdshangpai.utils.offlinecache.videocache;


import android.util.Log;

import com.cdshangpai.photoapp.LogConfig;
import com.cdshangpai.utils.api.Api;
import com.cdshangpai.utils.db.beans.Video;
import com.cdshangpai.utils.log.LogUtil;
import com.cdshangpai.utils.offlinecache.DbVersion;
import com.cdshangpai.utils.offlinecache.base.BaseCacheProcessor;
import com.cdshangpai.utils.offlinecache.base.DataDownloader;
import com.cdshangpai.utils.offlinecache.base.query.VideoQuery;

import java.util.List;

/**
 * 视频本地数据缓存处理其
 */
public class VideoCacheProcess {
    private VideoQuery videoQuery;
    Api api;

    public VideoCacheProcess()
    {
        videoQuery=new VideoQuery();
        api=new Api();
    }
    public boolean begin(List<DbVersion> serverVideoVersions)
    {
        DataDownloader dataDownloader=new DataDownloader() {
            @Override
            public List download(List ids) {
                return api.queryVideo(ids);
            }
        };
        List<Video> localDatas=videoQuery.query();
        LogUtil.save("开始同步视频...");
        Log.i(LogConfig.logTag,"开始同步视频...");
        return new BaseCacheProcessor<Video>()
                .setDbQuery(videoQuery)
                .setDataDownloader(dataDownloader)
                .setLocalDatas(localDatas)
                .setServerVersion(serverVideoVersions)
                .forVideo()
                .begin();

    }
}
